#pragma once

#include <QtWidgets/QPushButton>
#include <QtWidgets/QLabel>
#include <QtWidgets/QWidget>
#include <QtWidgets/QTextEdit>
#include <QtWidgets/QGridLayout>
#include <QtWidgets/QGroupBox>
#include <QtNetwork/QTcpServer>
#include <QtNetwork/QTcpSocket>

class TcpServer :
    public QWidget
{
    Q_OBJECT
public:
    TcpServer(int,QWidget*parent=nullptr);
    ~TcpServer();

private:
    QPushButton* btn_start = nullptr, * btn_stop = nullptr, * btn_send = nullptr;
    QGridLayout* mainLayout = nullptr,
        * top_layout = nullptr,
        * bottom_layout = nullptr,
        * center_layout = nullptr;
    QGroupBox* centerBox = nullptr, * topBox = nullptr,*bottomBox=nullptr;

    QLabel* lb_status = nullptr, * lb_port = nullptr,* lb_numclient = nullptr;
    QTextEdit* t_receive = nullptr, * t_send = nullptr;

    QTcpServer* server = nullptr;

    QList<QTcpSocket*> list_socket;

    int port;

    void initServer(int);
    void initGUI();

    void OnConnected();
    void On_Send();
    void On_Stop();
    void On_Start();
};

